import utilsIs from './index';

describe('UtilsIs', () => {
    let utilsIsInstance: any;

    beforeEach(() => {
        utilsIsInstance = utilsIs;
    });

    test('oddNumber should return true for odd numbers', () => {
        expect(utilsIsInstance.oddNumber(1)).toBe(true);
        expect(utilsIsInstance.oddNumber(3)).toBe(true);
    });

    test('oddNumber should return false for even numbers', () => {
        expect(utilsIsInstance.oddNumber(2)).toBe(false);
        expect(utilsIsInstance.oddNumber(4)).toBe(false);
    });

    test('evenNumber should return true for even numbers', () => {
        expect(utilsIsInstance.evenNumber(2)).toBe(true);
        expect(utilsIsInstance.evenNumber(4)).toBe(true);
    });

    test('evenNumber should return false for odd numbers', () => {
        expect(utilsIsInstance.evenNumber(1)).toBe(false);
        expect(utilsIsInstance.evenNumber(3)).toBe(false);
    });

    test('array should return true for arrays', () => {
        expect(utilsIsInstance.array([])).toBe(true);
        expect(utilsIsInstance.array([1, 2, 3])).toBe(true);
    });

    test('array should return false for non-arrays', () => {
        expect(utilsIsInstance.array(123)).toBe(false);
        expect(utilsIsInstance.array('abc')).toBe(false);
    });

    test('json should return true for JSON objects', () => {
        expect(utilsIsInstance.json({})).toBe(true);
        expect(utilsIsInstance.json({key: 'value'})).toBe(true);
    });

    test('json should return false for non-JSON objects', () => {
        expect(utilsIsInstance.json(123)).toBe(false);
        expect(utilsIsInstance.json('abc')).toBe(false);
        expect(utilsIsInstance.json([])).toBe(false);
    });

    test('integer should return true for integers with default params', () => {
        expect(utilsIsInstance.integer(1)).toBe(true);
        expect(utilsIsInstance.integer(0)).toBe(true);
        expect(utilsIsInstance.integer(-1)).toBe(true);
    });

    test('integer should return false for non-integers with default params', () => {
        expect(utilsIsInstance.integer(1.5)).toBe(false);
        expect(utilsIsInstance.integer('abc')).toBe(false);
    });

    test('integer should return false for zero with isCanZero set to false', () => {
        expect(utilsIsInstance.integer(0, {isCanZero: false})).toBe(false);
    });

    test('integer should return false for negative numbers with isCanNegativeNum set to false', () => {
        expect(utilsIsInstance.integer(-1, {isCanNegativeNum: false})).toBe(false);
    });

    test('number should return true for numbers with default params', () => {
        expect(utilsIsInstance.number(1)).toBe(true);
        expect(utilsIsInstance.number(0)).toBe(true);
        expect(utilsIsInstance.number(-1)).toBe(true);
        expect(utilsIsInstance.number(1.5)).toBe(true);
    });

    test('number should return false for non-numbers with default params', () => {
        expect(utilsIsInstance.number('abc')).toBe(false);
    });

    test('number should return false for non-integers with isInteger set to true', () => {
        expect(utilsIsInstance.number(1.5, {isInteger: true})).toBe(false);
    });

    test('number should return false for zero with isCanZero set to false', () => {
        expect(utilsIsInstance.number(0, {isCanZero: false})).toBe(false);
    });

    test('number should return false for negative numbers with isCanNegativeNum set to false', () => {
        expect(utilsIsInstance.number(-1, {isCanNegativeNum: false})).toBe(false);
    });

    test('amount should return the same result as number', () => {
        expect(utilsIsInstance.amount(12345.67, {isCanZero: true, isCanNegativeNum: true})).toBe(true);
        expect(utilsIsInstance.amount("12345.67", {isCanZero: true, isCanNegativeNum: true})).toBe(true);
        expect(utilsIsInstance.amount(1)).toBe(utilsIsInstance.number(1));
        expect(utilsIsInstance.amount(0)).toBe(utilsIsInstance.number(0));
        expect(utilsIsInstance.amount(-1)).toBe(utilsIsInstance.number(-1));
        expect(utilsIsInstance.amount(1.5)).toBe(utilsIsInstance.number(1.5));
    });

    test('firstStr should return true when value is at the first position', () => {
        expect(utilsIsInstance.firstStr('hello world', 'hello')).toBe(true);
        expect(utilsIsInstance.firstStr('hello world', ['hello', 'hi'])).toBe(true);
    });

    test('firstStr should return false when value is not at the first position', () => {
        expect(utilsIsInstance.firstStr('hello world', 'world')).toBe(false);
        expect(utilsIsInstance.firstStr('hello world', ['world', 'hi'])).toBe(false);
    });

    test('lastStr should return true when value is at the last position', () => {
        expect(utilsIsInstance.lastStr('hello world', 'world')).toBe(true);
        expect(utilsIsInstance.lastStr('hello world', ['world', 'hi'])).toBe(true);
    });

    test('lastStr should return false when value is not at the last position', () => {
        expect(utilsIsInstance.lastStr('hello world', 'hello')).toBe(false);
        expect(utilsIsInstance.lastStr('hello world', ['hello', 'hi'])).toBe(false);
    });
});
